
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "reflecxx.h"

int main(int argc, char *argv[])
{
    char buffer[1024], expected[1024];
    struct reflecxx_full_type rft;
    int retval = EXIT_SUCCESS;

    rft.rft_type = RT_CHAR;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 'a'));
    snprintf(expected, sizeof(expected), "%d", 'a' & 0xff);
    assert(strcmp(buffer, expected) == 0);

    rft.rft_type = RT_SHORT;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, (short)123));
    assert(strcmp(buffer, "123") == 0);
    
    rft.rft_type = RT_INT;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, (int)-1234));
    assert(strcmp(buffer, "-1234") == 0);
    
    rft.rft_type = RT_LONG;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 234L));
    assert(strcmp(buffer, "234") == 0);
    
    rft.rft_type = RT_LONG_LONG;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 232524LL));
    assert(strcmp(buffer, "232524") == 0);
    
    rft.rft_type = RT_FLOAT;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 1234.5f));
    assert(strcmp(buffer, "1234.500000") == 0);
    
    rft.rft_type = RT_DOUBLE;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 234.5));
    assert(strcmp(buffer, "234.500000") == 0);
    
    rft.rft_type = RT_UNSIGNED_CHAR;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 'a'));
    snprintf(expected, sizeof(expected), "%d", 'a' & 0xff);
    assert(strcmp(buffer, expected) == 0);

    rft.rft_type = RT_UNSIGNED_SHORT;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, (short)123));
    assert(strcmp(buffer, "123") == 0);
    
    rft.rft_type = RT_UNSIGNED_INT;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, (int)1234));
    assert(strcmp(buffer, "1234") == 0);
    
    rft.rft_type = RT_UNSIGNED_LONG;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 234UL));
    assert(strcmp(buffer, "234") == 0);
    
    rft.rft_type = RT_UNSIGNED_LONG_LONG;
    assert(reflecxx_print(buffer, sizeof(buffer), &rft, 232524ULL));
    assert(strcmp(buffer, "232524") == 0);
    
    return retval;
}
